﻿
@{
    Layout = null;
}

<!DOCTYPE html>


<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>缓存管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/favicon.ico">
    <link rel="stylesheet" href="/resources/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
    <!-- 查询条件开始 -->
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 5px;">
        <legend>缓存管理</legend>
    </fieldset>
    <!-- 数据表格开始 -->
    <div>
        <table class="layui-hide" id="cacheTable" lay-filter="cacheTable"></table>
        <div id="cacheToolBar" style="display: none;">
            <button type="button" lay-event="removeAll" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-delete"></span>清空缓存</button>
            <button type="button" lay-event="syncCache" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-about"></span>同步缓存</button>
        </div>

        <div id="cacheRowBar" style="display: none;">
            <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger"><span class="layui-icon layui-icon-delete"></span>删除</button>
        </div>
    </div>
    <!-- 数据表格结束 -->


    <script type="text/javascript" src="/resources/layui/layui.js"></script>
    <script type="text/javascript">
	layui.use(['jquery','form','table','layer'],function(){
		var $=layui.jquery;
		var form=layui.form;
		var table=layui.table;
		var layer=layui.layer;
		//加载 数据
		var tableIns=table.render({
			 elem: '#cacheTable'
		    ,url:'/cache/loadAllCache'
		    ,toolbar: '#cacheToolBar' //开启头部工具栏，并为其绑定左侧模板
		    ,title: '缓存数据表'
		    ,page: true
		    ,cols: [ [
		      {field:'key', title:'ID',align:'center',width:'100'}
		      ,{field:'value', title:'标题',align:'center',width:'1000'}
		      ,{fixed: 'right', title:'操作', toolbar: '#cacheRowBar',align:'center',width:'100'}
		    ] ]
		});

		//监听工具条的事件
		table.on("toolbar(cacheTable)",function(obj){
			 switch(obj.event){
			    case 'removeAll':
			       removeAll();
			    break;
			    case 'syncCache':
			       syncCache();
			    break;
			  };
		});

		//监听行工具条的事件
		table.on("tool(cacheTable)",function(obj){
			  var data = obj.data; //获得当前行数据
			 switch(obj.event){
			    case 'delete':
			   		deleteCache(data);
			    break;
			  };
		});

		//删除
		function deleteCache(data){
			layer.confirm('你确定要删除【'+data.key+'】这条缓存吗?', {icon: 3, title:'提示'}, function(index){
				$.post("/cache/deleteCache",{key:data.key},function(res){
					if(res.code==200){
						tableIns.reload();
					}
					layer.msg(res.msg);
				})
			   layer.close(index);
			});
		}

		//清空缓存
		function removeAll(){
			layer.confirm('你确定要清空所有缓存数据吗?', {icon: 3, title:'提示'}, function(index){
					$.post("/cache/removeAllCache",function(res){
						if(res.code==200){
							tableIns.reload();
						}
						layer.msg(res.msg);
					})
				   layer.close(index);
				});
		}
		//同步缓存
		function syncCache(){
			layer.confirm('你确定要同步所有缓存数据吗?', {icon: 3, title:'提示'}, function(index){
					$.post("/cache/syncCache",function(res){
						if(res.code==200){
							tableIns.reload();
						}
						layer.msg(res.msg);
					})
				   layer.close(index);
				});
		}
	});
    </script>

</body>
</html>